package com.tedu.pm;

import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;

public class Test {
    public static void main(String[] args) {
        //1、创建对象

        //List是接口

        List<Integer> list = new ArrayList<>();

        //2、常用方法

        list.add(100);

        list.add(101);

        list.add(102);

        list.add(103);

        list.add(102);

        list.add(105);



        System.out.println(list);



//     list.clear();

        System.out.println(list.contains(100));

        System.out.println(list.equals(101));

        System.out.println(list.hashCode() );

        System.out.println( list.isEmpty() );

        System.out.println(list.remove(2) );

        System.out.println(list.size() );

        System.out.println(list.toArray() );



        //特有方法

        System.out.println(list+"======");

        System.out.println( list.indexOf(105) );

        System.out.println(list.lastIndexOf(102) );

        list.add(3,105);

        System.out.println(list);

        System.out.println(list.get(3));

        System.out.println(list.set(0,99));

        System.out.println(list);

        System.out.println(list.subList(2, 4));//含头不含尾，类似于String.subString()

        System.out.println(list);

        //遍历集合中元素

        //ListIterator继承了Iterator，并提供了更加完善的功能，除了正常向后遍历还增加了向前遍历的功能

        ListIterator it = list.listIterator();

        while(it.hasNext()) {

            Object obj = it.next();

            System.out.println(obj);

        }
        //TODO 子接口提供的遍历方式-如：向前遍历

    }

}

